package main

import (
	"fmt"
	"math/rand"
	"time"
)

/*
* Author: JacksonCoder
* CreateTime: 2025/5/22
 */

func Send(ch chan int){
	for{
		var value = rand.Intn(100)
		ch <- value
		fmt.Printf("send %d\n",value) // 这里没有延时
	}
}

func Recv(ch chan  int){
	for{
		value := <- ch
		fmt.Printf("Recv %d\n",value)
		time.Sleep(time.Second)
	}
}

func main(){
	var ch = make(chan int, 1)
	// 子协程循环读
	go Recv(ch)
	// 主协程循环写
	Send(ch)
}